<template>
  <el-container class="welcome-container">
    <el-header>
      <div class="logo">
        <img src="../assets/heima.b5a855ee.png" alt />
        <span>电商后台管理系统</span>
      </div>
      <el-button class="btn" type="info" size="mini" @click="logout">退出登录</el-button>
    </el-header>
    <el-container class="container">
      <el-aside :width="width">
        <div class="handle" @click="toggleMenu" :style="{ width: width }">| | |</div>
        <el-menu
          :default-active="defaultActive"
          class="el-menu-vertical-demo"
          background-color="#333744"
          text-color="#fff"
          active-text-color="#409eff"
          :unique-opened="true"
          :collapse="iscollapse"
          :collapse-transition="iscollapse"
          :router="true"
        >
          <el-submenu v-for="(item1, index1) in menuList" :key="index1" :index="'/'+item1.path">
            <template slot="title">
              <i :class="icon[item1.id]"></i>
              <span>{{ item1.authName }}</span>
            </template>
            <el-menu-item-group v-for="(item2, index2) in item1.children" :key="index2">
              <el-menu-item :index="'/'+item2.path" @click="handleOpen('/'+item2.path)">
                <i class="el-icon-menu"></i>
                {{ item2.authName }}
              </el-menu-item>
            </el-menu-item-group>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>
<script>
/* eslint-disable */
import { getmenuList_api } from '@/api/index.js'
export default {
  data() {
    return {
      iscollapse: false,
      width: '',
      defaultActive: window.sessionStorage.getItem('defaultActive') || 'users',
      menuList: null,
      icon: {
        '125': 'iconfont icon-user',
        '103': 'iconfont icon-tijikongjian',
        '101': 'iconfont icon-shangpin',
        '102': 'iconfont icon-danju',
        '145': 'iconfont icon-baobiao'
      }
    }
  },
  created() {
    this.getmenuList()
  },
  methods: {
    //退出
    logout() {
      window.sessionStorage.setItem('token', null)
      this.$router.push('/login')
    },
    //设置当前活跃的项目文本为高亮
    handleOpen(key) {
      console.log(key, 111)
      this.defaultActive = key //点击的path值
      window.sessionStorage.setItem('defaultActive', key)
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath, 222)
    },
    //获取左侧菜单列表
    async getmenuList() {
      var { data: res } = await getmenuList_api()
      console.log(res)
      this.menuList = res.data
    },
    //实现侧边导航切换
    toggleMenu() {
      this.iscollapse = !this.iscollapse
      this.width = this.iscollapse ? '60px' : '200px'
    }
  }
}
</script>
<style lang="less">
.welcome-container {
  height: 100%;

  .el-header {
    padding-left: 0px;
    background-color: #383d41;
    display: flex;
    justify-content: space-between;
    .logo {
      img {
        margin-right: 10px;
        vertical-align: middle;
      }
      span {
        font-size: 20px;
        color: #fff;
      }
    }

    .btn {
      height: 40px;
      margin-top: 10px;
    }
  }
  .container {
    display: flex;
    flex: 1;
    .el-aside {
      background-color: #333743;
      .handle {
        height: 20px;
        background-color: #4a5064;
        color: #fff;
        text-align: center;
        line-height: 20px;
        font-size: 10px;
      }
    }
    .el-main {
      flex: 1;
      background-color: #eaedf1;
    }
  }
}
</style>
